package views.features;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import views.util.GameColors;

public class MainMenuView extends FeatureView {

	private GridBagConstraints gbc = new GridBagConstraints();
	private JButton gameMenu = new JButton();
	private JButton classification;
	private JButton chronology;
	private JButton statistics;
	private ImageIcon gameMenuIcon = new ImageIcon(
			"resources\\mainMenu\\gioca.png");
	private ImageIcon classificationIcon = new ImageIcon(
			"resources\\mainMenu\\istruzioni.png");
	private ImageIcon chronologyIcon = new ImageIcon(
			"resources\\mainMenu\\calendar.png");
	private ImageIcon statisticsIcon = new ImageIcon(
			"resources\\mainMenu\\statistiche.png");
	private static MainMenuView instance;

	public static MainMenuView newInstance() {
		if (instance == null)
			instance = new MainMenuView();
		return instance;
	}

	private MainMenuView() {
		this.setLayout(new GridBagLayout());
		this.setBackground(Color.WHITE);
		gameMenu = new newButton(gameMenuIcon, "MENU GIOCHI");
		classification = new newButton(classificationIcon, "ISTRUZIONI");
		chronology = new newButton(chronologyIcon, "CRONOLOGIA");
		statistics = new newButton(statisticsIcon, "STATISTICHE");
		gameMenu.setName("gameMenu");
		classification.setName("classification");
		chronology.setName("chronology");
		statistics.setName("statistics");
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.insets = new Insets(-25, 10, 45, 10); // Modificato da (10,10,10,10)
													// per compensare la
													// presenza della barra
													// superiore
		add(gameMenu, gbc);
		gbc.gridx = 1;
		add(classification, gbc);
		gbc.gridx = 0;
		gbc.gridy = 1;
		add(chronology, gbc);
		gbc.gridx = 1;
		add(statistics, gbc);
	}

	public void addActionListenerToMenu(ActionListener a) {
		gameMenu.addActionListener(a);
		classification.addActionListener(a);
		chronology.addActionListener(a);
		statistics.addActionListener(a);
	}

	private class newButton extends JButton {

		private final Dimension DIM = new Dimension(250, 280);;
		private final Font FONT = new Font("Segoe UI", Font.BOLD, 18);

		public newButton(ImageIcon menuIcon, String text) {
			this.setPreferredSize(DIM);
			this.setIcon(menuIcon);
			this.setBackground(Color.WHITE);
			this.setHorizontalTextPosition(JButton.CENTER);
			this.setVerticalTextPosition(JButton.BOTTOM);
			this.setFont(FONT);
			this.setForeground(GameColors.BLU_CHIARO);
			this.setText(text);
		}

	}

}